home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / layout / nsStyleSet.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  10KB  |  270 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Daniel Glazman <glazman@netscape.com>
  24.  *   Brian Ryner    <bryner@brianryner.com>
  25.  *
  26.  * Alternatively, the contents of this file may be used under the terms of
  27.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  28.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  29.  * in which case the provisions of the GPL or the LGPL are applicable instead
  30.  * of those above. If you wish to allow use of your version of this file only
  31.  * under the terms of either the GPL or the LGPL, and not to allow others to
  32.  * use your version of this file under the terms of the MPL, indicate your
  33.  * decision by deleting the provisions above and replace them with the notice
  34.  * and other provisions required by the GPL or the LGPL. If you do not delete
  35.  * the provisions above, a recipient may use your version of this file under
  36.  * the terms of any one of the MPL, the GPL or the LGPL.
  37.  *
  38.  * ***** END LICENSE BLOCK ***** */
  39.  
  40. #ifndef nsStyleSet_h_
  41. #define nsStyleSet_h_
  42.  
  43. #include "nsIStyleRuleProcessor.h"
  44. #include "nsICSSStyleSheet.h"
  45. #include "nsVoidArray.h"
  46. #include "nsIStyleRuleSupplier.h"
  47. #include "nsRuleNode.h"
  48.  
  49. class nsIURI;
  50.  
  51. // The style set object is created by the document viewer and ownership is
  52. // then handed off to the PresShell.  Only the PresShell should delete a
  53. // style set.
  54.  
  55. class nsStyleSet
  56. {
  57.  public:
  58.   nsStyleSet();
  59.  
  60.   // Initialize the object.  You must check the return code and not use
  61.   // the nsStyleSet if Init() fails.
  62.  
  63.   nsresult Init(nsPresContext *aPresContext);
  64.  
  65.   // For getting the cached default data in case we hit out-of-memory.
  66.   // To be used only by nsRuleNode.
  67.   nsCachedStyleData* DefaultStyleData() { return &mDefaultStyleData; }
  68.  
  69.   // clear out all of the computed style data
  70.   void ClearStyleData(nsPresContext *aPresContext);
  71.  
  72.   // enable / disable the Quirk style sheet
  73.   void EnableQuirkStyleSheet(PRBool aEnable);
  74.  
  75.   // get a style context for a non-pseudo frame.
  76.   already_AddRefed<nsStyleContext>
  77.   ResolveStyleFor(nsIContent* aContent, nsStyleContext* aParentContext);
  78.  
  79.   // Get a style context for a non-element (which no rules will match).
  80.   // Eventually, this should go away and we shouldn't even create style
  81.   // contexts for such content nodes.  However, not doing any rule
  82.   // matching for them is a first step.
  83.   //
  84.   // XXX This is temporary.  It should go away when we stop creating
  85.   // style contexts for text nodes and placeholder frames.  (We also use
  86.   // it once to create a style context for the nsFirstLetterFrame that
  87.   // represents everything except the first letter.)
  88.   //
  89.   already_AddRefed<nsStyleContext>
  90.   ResolveStyleForNonElement(nsStyleContext* aParentContext);
  91.  
  92.   // get a style context for a pseudo-element (i.e.,
  93.   // |aPseudoTag == nsCOMPtr<nsIAtom>(do_GetAtom(":first-line"))|;
  94.   already_AddRefed<nsStyleContext>
  95.   ResolvePseudoStyleFor(nsIContent* aParentContent,
  96.                         nsIAtom* aPseudoTag,
  97.                         nsStyleContext* aParentContext,
  98.                         nsICSSPseudoComparator* aComparator = nsnull);
  99.  
  100.   // This funtions just like ResolvePseudoStyleFor except that it will
  101.   // return nsnull if there are no explicit style rules for that
  102.   // pseudo element.
  103.   already_AddRefed<nsStyleContext>
  104.   ProbePseudoStyleFor(nsIContent* aParentContent,
  105.                       nsIAtom* aPseudoTag,
  106.                       nsStyleContext* aParentContext);
  107.  
  108.   // Begin ignoring style context destruction, to avoid lots of unnecessary
  109.   // work on document teardown.
  110.   void BeginShutdown(nsPresContext* aPresContext);
  111.  
  112.   // Free all of the data associated with this style set.
  113.   void Shutdown(nsPresContext* aPresContext);
  114.  
  115.   // Notification that a style context is being destroyed.
  116.   void NotifyStyleContextDestroyed(nsPresContext* aPresContext,
  117.                                    nsStyleContext* aStyleContext);
  118.  
  119.   // Get a new style context that lives in a different parent
  120.   // The new context will be the same as the old if the new parent is the
  121.   // same as the old parent.
  122.   already_AddRefed<nsStyleContext>
  123.     ReParentStyleContext(nsPresContext* aPresContext,
  124.                          nsStyleContext* aStyleContext,
  125.                          nsStyleContext* aNewParentContext);
  126.  
  127.   // Test if style is dependent on content state
  128.   nsReStyleHint HasStateDependentStyle(nsPresContext* aPresContext,
  129.                                        nsIContent*     aContent,
  130.                                        PRInt32         aStateMask);
  131.  
  132.   // Test if style is dependent on the presence of an attribute.
  133.   nsReStyleHint HasAttributeDependentStyle(nsPresContext* aPresContext,
  134.                                            nsIContent*     aContent,
  135.                                            nsIAtom*        aAttribute,
  136.                                            PRInt32         aModType);
  137.  
  138.   // APIs for registering objects that can supply additional
  139.   // rules during processing.
  140.   void SetStyleRuleSupplier(nsIStyleRuleSupplier* aSupplier)
  141.   {
  142.     mStyleRuleSupplier = aSupplier;
  143.   }
  144.  
  145.   nsIStyleRuleSupplier* GetStyleRuleSupplier() const
  146.   {
  147.     return mStyleRuleSupplier;
  148.   }
  149.  
  150.   // Free global data at module shutdown
  151.   static void FreeGlobals() { NS_IF_RELEASE(gQuirkURI); }
  152.  
  153.   // The "origins" of the CSS cascade, from lowest precedence to
  154.   // highest (for non-!important rules).
  155.   enum sheetType {
  156.     eAgentSheet, // CSS
  157.     ePresHintSheet,
  158.     eUserSheet, // CSS
  159.     eHTMLPresHintSheet,
  160.     eDocSheet, // CSS
  161.     eStyleAttrSheet,
  162.     eOverrideSheet, // CSS
  163.     eSheetTypeCount
  164.     // be sure to keep the number of bits in |mDirty| below updated when
  165.     // changing the number of sheet types
  166.   };
  167.  
  168.   // APIs to manipulate the style sheet lists.  The sheets in each
  169.   // list are stored with the most significant sheet last.
  170.   nsresult AppendStyleSheet(sheetType aType, nsIStyleSheet *aSheet);
  171.   nsresult PrependStyleSheet(sheetType aType, nsIStyleSheet *aSheet);
  172.   nsresult RemoveStyleSheet(sheetType aType, nsIStyleSheet *aSheet);
  173.   nsresult ReplaceSheets(sheetType aType,
  174.                          const nsCOMArray<nsIStyleSheet> &aNewSheets);
  175.  
  176.   //Enable/Disable entire author style level (Doc & PresHint levels)
  177.   PRBool GetAuthorStyleDisabled();
  178.   nsresult SetAuthorStyleDisabled(PRBool aStyleDisabled);
  179.  
  180.   PRInt32 SheetCount(sheetType aType) const {
  181.     return mSheets[aType].Count();
  182.   }
  183.  
  184.   nsIStyleSheet* StyleSheetAt(sheetType aType, PRInt32 aIndex) const {
  185.     return mSheets[aType].ObjectAt(aIndex);
  186.   }
  187.  
  188.   nsresult AddDocStyleSheet(nsIStyleSheet* aSheet, nsIDocument* aDocument);
  189.  
  190.   void     BeginUpdate();
  191.   nsresult EndUpdate();
  192.  
  193.  private:
  194.   // Not to be implemented
  195.   nsStyleSet(const nsStyleSet& aCopy);
  196.   nsStyleSet& operator=(const nsStyleSet& aCopy);
  197.  
  198.   // Returns false on out-of-memory.
  199.   PRBool BuildDefaultStyleData(nsPresContext* aPresContext);
  200.  
  201.   // Update the rule processor list after a change to the style sheet list.
  202.   nsresult GatherRuleProcessors(sheetType aType);
  203.  
  204.   void AddImportantRules(nsRuleNode* aCurrLevelNode,
  205.                          nsRuleNode* aLastPrevLevelNode);
  206.  
  207. #ifdef DEBUG
  208.   // Just like AddImportantRules except it doesn't actually add anything; it
  209.   // just asserts that there are no important rules between aCurrLevelNode and
  210.   // aLastPrevLevelNode.
  211.   void AssertNoImportantRules(nsRuleNode* aCurrLevelNode,
  212.                               nsRuleNode* aLastPrevLevelNode);
  213.   
  214.   // Just like AddImportantRules except it doesn't actually add anything; it
  215.   // just asserts that there are no CSS rules between aCurrLevelNode and
  216.   // aLastPrevLevelNode.  Mostly useful for the preshint levels.
  217.   void AssertNoCSSRules(nsRuleNode* aCurrLevelNode,
  218.                         nsRuleNode* aLastPrevLevelNode);
  219. #endif
  220.   
  221.   // Enumerate the rules in a way that cares about the order of the
  222.   // rules.
  223.   void FileRules(nsIStyleRuleProcessor::EnumFunc aCollectorFunc,
  224.                  RuleProcessorData* aData);
  225.  
  226.   // Enumerate all the rules in a way that doesn't care about the order
  227.   // of the rules and break out if the enumeration is halted.
  228.   void WalkRuleProcessors(nsIStyleRuleProcessor::EnumFunc aFunc,
  229.                           RuleProcessorData* aData);
  230.  
  231.   already_AddRefed<nsStyleContext> GetContext(nsPresContext* aPresContext,
  232.                                               nsStyleContext* aParentContext,
  233.                                               nsIAtom* aPseudoTag);
  234.  
  235.   nsPresContext* PresContext() { return mRuleTree->GetPresContext(); }
  236.  
  237.   static nsIURI  *gQuirkURI;
  238.  
  239.   nsCOMArray<nsIStyleSheet> mSheets[eSheetTypeCount];
  240.  
  241.   nsCOMPtr<nsIStyleRuleProcessor> mRuleProcessors[eSheetTypeCount];
  242.  
  243.   // cached instance for enabling/disabling
  244.   nsCOMPtr<nsIStyleSheet> mQuirkStyleSheet;
  245.  
  246.   nsCOMPtr<nsIStyleRuleSupplier> mStyleRuleSupplier;
  247.  
  248.   // To be used only in case of emergency, such as being out of memory
  249.   // or operating on a deleted rule node.  The latter should never
  250.   // happen, of course.
  251.   nsCachedStyleData mDefaultStyleData;
  252.  
  253.   nsRuleNode* mRuleTree; // This is the root of our rule tree.  It is a
  254.                          // lexicographic tree of matched rules that style
  255.                          // contexts use to look up properties.
  256.   nsRuleWalker* mRuleWalker; // This is an instance of a rule walker that can
  257.                              // be used to navigate through our tree.
  258.  
  259.   PRInt32 mDestroyedCount; // used to batch style context GC
  260.   nsVoidArray mRoots; // style contexts with no parent
  261.  
  262.   PRUint16 mBatching;
  263.  
  264.   unsigned mInShutdown : 1;
  265.   unsigned mAuthorStyleDisabled: 1;
  266.   unsigned mDirty : 7;  // one dirty bit is used per sheet type
  267. };
  268.  
  269. #endif
  270.